
public class textEngine {
	
	public static final String newline = System.getProperty("line.separator");
	
	private board _board;
	
	public textEngine(board b) { _board = b; }
	
	//return a string representing the whole board with current bitmask state
	public String toStringState() {
		String t = "";
		for (int i=0; i < 81; i++) { t += String.format("%03d", _board.cells.get(i).getBitmask()); }	
		return t;
	}
	
	//return a string representing the whole board (human-friendly compact)
	public String toStringVals() {
		String t = "";
		for (int i=0; i < 81; i++) { t += _board.cells.get(i).getValue(); }
		t = t.replaceAll("0", ".");
		return toStringCompact(t);
	}
	
	private String toStringCompact(String s) {
		String t = "";
		for (int i=0; i < 9; i++) {
			t += s.substring(i*9, i * 9 + 9) + newline;
		}
		return t;
	}
	
	public String toStringFull() {
		String DoubleLine = " ######################################################################### ";
		String SingleLine = " #-------+-------+-------#-------+-------+-------#-------+-------+-------# ";
		String t = DoubleLine + newline;
		
		//loop the rows
		for (int r = 0; r < 9; r++) {
			
			//loop through each column 3 times for the 3-linees of each cell (123,456,789)
			for (int x = 0; x < 3; x++) {
				//loop the column for the top row of each cell
				for (int c = 0; c < 9; c++) {
					switch (c) {
						case 0: case 3: case 6: t += " # "; break;
						default: t += " | "; break;
					}
					
					cell e = _board.rows[r].get(c);
					
					if (e.getValue() == 0) {
						String t2 = e.toString().substring(3*x, 3*x+3);
						String t3 =  t2.charAt(0) + " " + t2.charAt(1) + " " + t2.charAt(2);
						t += t3;
					}
					else { t+= (x == 1) ? "  " + e.getValue() + "  " : "     "; }
					
				}
				t += " # " + newline;
			}

			switch (r) {
				case 2: case 5: case 8: t += DoubleLine + newline; break;
				default: t += SingleLine + newline; break;
			}
		}
		
		return t;
	}

}
